home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / Apple Guide / Engineering / APISample / APISampleCW / Source / UAppMo.h < prev    next >
Encoding:
Text File  |  1994-05-26  |  6.1 KB  |  213 lines  |  [TEXT/MPS ]

  1. // Copyright ©1994 Apple Computer, Inc.
  2. // Author: John Powers
  3. // Date:   13-Mar-94
  4.  
  5. // UAppMo.h
  6. // Header for our main program for MoGuide.
  7. // Contains all our derived classes and our new classes.
  8.  
  9. #ifndef __UAPPMO__
  10. #define __UAPPMO__                // #endif __UAPPMO__ is at end of this file
  11.  
  12. // Most of the includes are covered in UApp.h
  13.  
  14. #include <GestaltEqu.h>            // Gestalt
  15. #include <Menus.h>
  16.  
  17. #ifndef __UAPP__
  18.     #include "UApp.h"
  19. #endif
  20.  
  21. #ifndef __UDOCMO__
  22.     #include "UDocMo.h"
  23. #endif
  24.  
  25.         // Constants (also see UAppShared.h).
  26.  
  27. #define    override virtual
  28.  
  29.  
  30. #define FRONT_WINDOW  ((WindowPtr) (-1L))
  31.  
  32. // ------------------------------------------------------------------------
  33.  
  34.  
  35.         // Forward references
  36.  
  37. class TAppMo;
  38. class TDoc;
  39. class TDocClip;
  40. class TDocArt;
  41. class TDocFB;
  42.  
  43. // ------------------------------------------------------------------------
  44. // TTypeStr
  45. // Makes a string from a type.
  46.  
  47. typedef union {
  48.     OSType            type;
  49.     unsigned char    ch[4];
  50. } TypeToChar, CharToType;
  51.  
  52. class TTypeStr
  53. {
  54.     private:
  55.         unsigned char    fString[5];
  56.     protected:
  57.     public:
  58.         TTypeStr(OSType theType);            // Constructor
  59.         StringPtr String();
  60. };
  61.  
  62. // ------------------------------------------------------------------------
  63. // TFeedback
  64. // Flashes a 4-character string for a predefined interval.
  65. //
  66. // Instantiate a TFeedback object.
  67. // Init the object with the application object and the TFeedback index.
  68. // SetDoc when the feedback document is created.
  69. // SetDoc with nil when the feedback document is deleted.
  70. // GetBeep and SetBeep as desired (default is false, no beep.)
  71. // SetInterval only if the default (kIntervalShow) is not desired.
  72. // Set a interval of 0, for an infinite interval.
  73. // SetFlash with the data to feedback. Pass OSType, Ptr, or Str255.
  74. // DoIdle in the Idle loop (does the drawing of the feedback data.)
  75. //
  76. // Time is measured in ticks.
  77. //
  78. class TFeedback
  79. {
  80.     private:
  81.         enum {
  82.             kIntervalShow = 120,
  83.             kPaint = patCopy,
  84.             kErase = patBic
  85.         };
  86.         short        fWhichData;    // Index for display location of data
  87.         long        fShowTime;    // Last time data was shown.
  88.         long        fInterval;    // Time interval to show data before erasing.
  89.         OSType        fCurrent;    // Current data to show
  90.         OSType        fPrevious;    // Data previously shown
  91.         Boolean        fShow;        // true if we want to show data
  92.         Boolean        fBeep;        // true if we want a beep
  93.         TAppMo*        fOurApp;    // Collaborator
  94.         TDocFB*        fDocFB;        // Feedback window collaborator
  95.         virtual void Draw(OSType toDraw, short mode);
  96.         virtual void Show();
  97.     protected:
  98.     public:
  99.         TFeedback();                // Constructor
  100.         virtual ~TFeedback();    // Destructor
  101.         virtual void DoIdle();
  102.         virtual Boolean GetBeep();
  103.         virtual void SetBeep(Boolean wantBeep);
  104.         virtual void SetFlash(OSType theFlash);
  105.         virtual void SetFlash(Ptr theFlash);
  106.         virtual void SetFlash(Str255 theFlash);
  107.         virtual void SetDoc(TDocFB* doc) {this->fDocFB = doc;}
  108.         virtual void SetInterval(short interval) {this->fInterval = interval;}
  109.         virtual void Init(TAppMo* theApp, short whichData);
  110. };
  111.  
  112. // ------------------------------------------------------------------------
  113. // TContext
  114. // Completely encapsulates all the context checking from Apple Guide.
  115.  
  116. class TContext
  117. {
  118.     private:
  119.         enum {
  120.             kContextHandlerCnt =    3,
  121.             kAEIdContextCollision =    'WiYe',
  122.             kAEIdContextBeep =        'WiYf',
  123.             kAEIdContextWindow =    'WiYg'
  124.         };
  125.         struct ContextCheck {
  126.             AEEventID        eventID;
  127.             AGContextRefNum    refNum;
  128.         };
  129.         short            fHandlerCnt;                    // No.of handlers
  130.         ContextCheck    fContext[kContextHandlerCnt];    // Context
  131.     protected:
  132.     public:
  133.         TContext();                // Constructor
  134.         virtual ~TContext();    // Destructor
  135.         virtual OSErr Install(long appObj);
  136.         virtual OSErr Remove();
  137.         static pascal OSErr ReplyToContext(Ptr pInput,
  138.                                             Size inputDataSize,
  139.                                             Ptr *ppOutput,
  140.                                             Size *pOutputDataSize,
  141.                                             AGAppInfoHdl hAppInfo);
  142. };
  143.  
  144. // ------------------------------------------------------------------------
  145. // Derive our application class from the application base class.
  146. // Add the About dialog, initialization, and a menu.
  147.  
  148. class TAppMo : public TApp
  149. {
  150.     friend class TContext;    // To give access to our private parts.
  151.     private:
  152.         enum {    
  153.                     // Custom event class and id's
  154.                     // Context events are in TContext.
  155.             kAEClassCustom =        'MoHC',
  156.             kAEIdCloseDocArt =        'MoCa',
  157.             kAEIdShowDocArt =        'MoSa',
  158.             kAEIdCloseDocFB =        'MoCf',
  159.             kAEIdShowDocFB =        'MoSf',
  160.             kAEIdReset =            'MoRs',
  161.             kAEIdShuffle =            'MoSh',
  162.             kAEIdQuitApp =            'MoQa',
  163.             kAEIdWaitCollision =    'MoAw',
  164.             kAEIdIgnoreCollision =    'MoAi',
  165.             kAEIdAdvance =            'MoAa',
  166.                     // Maximum cycles between status updates.
  167.             kMaxStatusUpdateCnt =     100
  168.         };
  169.         AGCoachRefNum    fCoachRefNum;    // Coach handler
  170.         TContext*        fContext;        // Context handler object
  171.         Handle        fhFileList;        // Handle of FSSpecs for guide files.
  172.         short        fFileCount;        // Number of guide files.
  173.         Boolean        fBeepReturn;    // Reply to kAEIdContextBeep query.
  174.         Boolean        fOkayAdvance;    // True if a panel advance is okay.
  175.         short        fLastMiscIndex;    // Last index for FBMisc string.
  176.         short        fLastStatusCnt;    // Last status update counter.
  177.         TFeedback*    fFBContext;        // Context feedback
  178.         TFeedback*    fFBCoach;        // Coach feedback
  179.         TFeedback*    fFBEvent;        // Event feedback
  180.         TFeedback*    fFBMisc;        // Miscellaneous feedback
  181.         TDocArt*    fDocArt;        // Our current art document window
  182.         TDocFB*        fDocFB;            // Feedback document window
  183.             // New functions.
  184.         virtual void CheckFrontWindow();
  185.     protected:
  186.             // New functions.
  187.         virtual void AddGuideFiles();
  188.         static pascal OSErr ReplyToCoach(Rect* pItemRect,
  189.                                             Ptr pName,
  190.                                             long refCon);
  191.         virtual void ShowArt();
  192.         virtual void ShowFeedback();
  193.             // Overrides
  194.         override void AdjustMenus();
  195.         override void DoGoAway();
  196.         override void DoIdle();
  197.         override void DoMenuCommand(short menuID, short menuItem);
  198.         override OSErr Start();
  199.     public:
  200.         TAppMo();                    // Constructor
  201.             // New functions.
  202.         virtual void DoAdvance();
  203.         virtual TDocArt* GetDocArt() {return this->fDocArt;}
  204.         static pascal OSErr HandleAECustom(AppleEvent& theAppleEvent,
  205.                                             AppleEvent& theReply,
  206.                                             long refCon);
  207.         virtual void SetOkayAdvance(Boolean isOkay) {this->fOkayAdvance=isOkay;}
  208.             // Overrides
  209.         override OSErr Init();
  210.         override void Quit();
  211. };
  212.  
  213. #endif __UAPPMO__